package com.hellogood.yaohuo.server.serviceImpl;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.hellogood.yaohuo.server.mgr.factory.MgrFactory;
import com.hellogood.yaohuo.shared.entity.Form;
import com.hellogood.yaohuo.shared.entity.ThForm;
import com.hellogood.yaohuo.shared.services.FanchangService;

public class FanchangServiceImpl extends RemoteServiceServlet implements FanchangService {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3732359963091006819L;

	@Override
	public List<Form> searchFanchangFormByOrgCodeAndDate(String orgCode, int level, String startDate, String endDate, String rz) {
		return MgrFactory.getInstance().createFanchangMgr().searchFanchangFormByOrgCodeAndDate(orgCode, level, startDate, endDate, rz);
	}

	@Override
	public Form getFormDetail(String billNo) {
		return MgrFactory.getInstance().createFanchangMgr().getFormDetail(billNo);
	}

	@Override
	public String deleteForm(String billNo) {
		return MgrFactory.getInstance().createFanchangMgr().deleteForm(billNo);
	}

	@Override
	public String saveForm(ThForm form, boolean isModify) {
		return MgrFactory.getInstance().createFanchangMgr().saveForm(form, isModify);
	}

	@Override
	public String bankForm(List<String> bills) {
		return MgrFactory.getInstance().createFanchangMgr().rz(bills);
	}

	@Override
	public String getLastFcBillNo(String orgCode) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		DecimalFormat df = new DecimalFormat("0000");
		String billNo = "WLFC" + sdf.format(new Date());
		int lastNo = MgrFactory.getInstance().createFanchangMgr().getLastFcBillNo(billNo);
		lastNo++;
		billNo += df.format(lastNo);
		return billNo;
	}

}
